/*
 * Copyright (c) United Binary LLC.  All rights reserved.
 * 
 * This code is licensed under the MIT License
 * 
 * SEE: http://harnessit.codeplex.com/license
 * 
 */
using System;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace UnitedBinary.UnitTests.Framework.TestItems
{
	/// <include file='comments.xml' path='Docs/TestExceptionType/Class/*'/>
	[Serializable]
	[EditorBrowsable(EditorBrowsableState.Never)]
	public class TestExceptionType
	{
		private string myType = "";
		private TestExceptionType myBaseType = null;

		/// <include file='comments.xml' path='Docs/TestExceptionType/ctor/*'/>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public TestExceptionType()
		{
		}

		/// <include file='comments.xml' path='Docs/TestExceptionType/ctor_Type/*'/>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public TestExceptionType(System.Type type)
		{
			if (type == null)
			{
				throw new ArgumentNullException("Type", "Type cannot be null.");
			}

			//
			// The error handling here may seem over done. However, certain situations,
			// usually strange MC++ types, can throw weird exceptions even in the ToString()
			// method of type.
			//

			try
			{
				string typeString = type.ToString();
				if (typeString != null)
				{
					this.myType = typeString;
				}
				else
				{
					this.myType = "null";
				}
			}
			catch 
			{
				this.myType = "unavailable";
			}

			try
			{
				if (type.BaseType != null)
				{
					this.ExceptionBaseType = new TestExceptionType(type.BaseType);
				}
			}
			catch { }
		}

		/// <include file='comments.xml' path='Docs/TestExceptionType/ExceptionType/*'/>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public string ExceptionType
		{
			get
			{
				return myType;
			}
			set
			{
				myType = value;
			}
		}

		/// <include file='comments.xml' path='Docs/TestExceptionType/ExceptionBaseType/*'/>
		[EditorBrowsable(EditorBrowsableState.Never)]
		public TestExceptionType ExceptionBaseType
		{
			get
			{
				return myBaseType;
			}
			set
			{
				myBaseType = value;
			}
		}
	}
}
